<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\GkyWeAccount;

/**
 * GkyWeAccountSearch represents the model behind the search form about `app\models\GkyWeAccount`.
 */
class GkyWeAccountSearch extends GkyWeAccount
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'wetype', 'addtime', 'atexpiretime', 'jsapiexpiretime'], 'integer'],
            [['wename', 'weno', 'weoid', 'weappid', 'wesecret', 'weadskey', 'qrcode', 'accesstoken', 'wetoken', 'wemenu', 'jsapiticket'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = GkyWeAccount::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'wetype' => $this->wetype,
            'addtime' => $this->addtime,
            'atexpiretime' => $this->atexpiretime,
            'jsapiexpiretime' => $this->jsapiexpiretime,
        ]);

        $query->andFilterWhere(['like', 'wename', $this->wename])
            ->andFilterWhere(['like', 'weno', $this->weno])
            ->andFilterWhere(['like', 'weoid', $this->weoid])
            ->andFilterWhere(['like', 'weappid', $this->weappid])
            ->andFilterWhere(['like', 'wesecret', $this->wesecret])
            ->andFilterWhere(['like', 'weadskey', $this->weadskey])
            ->andFilterWhere(['like', 'qrcode', $this->qrcode])
            ->andFilterWhere(['like', 'accesstoken', $this->accesstoken])
            ->andFilterWhere(['like', 'wetoken', $this->wetoken])
            ->andFilterWhere(['like', 'wemenu', $this->wemenu])
            ->andFilterWhere(['like', 'jsapiticket', $this->jsapiticket]);

        return $dataProvider;
    }
}
